package com.taobao.action;

import com.taobao.pojo.TBMessage;
import com.taobao.server.ConfigServer;
import com.taobao.server.impl.ConfigServerImpl;
import com.taobao.tools.Resource;
import com.taobao.tools.TBMessageDialog;
import com.taobao.ui.LoginUI;

public class AssistantAction {

    private ConfigServer configServer = new ConfigServerImpl();

    public void doAction(Object uiObject) {
        LoginUI loginUI = (LoginUI) uiObject;
        loginUI.setStatusText("", Resource.LOAD_CONFIG_ING);
        TBMessage message = configServer.load();
        TBMessageDialog.messageHandler(loginUI.getShell(), message);
        int code = message.getCode();
        if (code == TBMessage.SUCCESS) {
            loginUI.setWidgetEnable();
            loginUI.setComboValue();
        } else {
            loginUI.setStatusText(Resource.LOAD_CONFIG_ING, Resource.LOAD_CONFIG_FAIL);
            this.lock();
        }
    }

    private void lock() {
        synchronized (configServer) {
            try {
                configServer.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
